package addon.w3.mdx.com;

import java.io.IOException;
import java.util.Vector;

import addon.w3.mdx.MDXCOM;
import addon.w3.mdx.LEDataInputStream;
import addon.w3.mdx.MDXException;

/**
	struct {
		long	nbytesi;
		OBJ
		long	Type			(0:Omnidirectional;1:Directional;2:Ambient)
		float	AttStart, AttEnd;
		float	ColR, ColG, ColB;
		float	Intensity;
		float	AmbColR, AmbColG, AmbColB;
		float	AmbIntensity;
		(KLAI)
		(KLAV)
		(KLAC)
		(KLBC)
		(KLBI)
	} lights[nlits];
 * @author madjk
 *
 */
public class MDXLightCOM extends MDXCOM {
	int nbytesi = -1;
	MDXObject obj;
	int type = -1;
	float attStart, attEnd;
	float colR,colG,colB;
	float intensity;
	float ambColR, ambColG, ambColB;
	float ambIntensity;
	
	MDXAlpha klai;
	MDXAlpha klav;
	MDXScaling klac;
	MDXScaling klbc;
	MDXAlpha klbi;
	
	public String getTag() {
		return "LITE:light";
	}
	
	public void _decode(LEDataInputStream ins) throws IOException, MDXException {
		nbytesi = ins.readInt();
		(obj = new MDXObject()).decode(ins);
		type = ins.readInt();
		attStart = ins.readFloat();
		attEnd = ins.readFloat();
		colR = ins.readFloat();
		colG = ins.readFloat();
		colB = ins.readFloat();
		intensity = ins.readFloat();
		ambColR = ins.readFloat();
		ambColG = ins.readFloat();
		ambColB = ins.readFloat();
		ambIntensity = ins.readFloat();
		
		String tag = null;
		byte temp[] = new byte[4];
		ins.read(temp);
		tag = new String(temp);
		if(tag.equals("KLAI")) {
			klai = new MDXAlpha("KLAI","KLAI:Intensity");
			klai.decode(ins);
		} else ins.unread(temp);
		
		ins.read(temp);
		tag = new String(temp);
		if(tag.equals("KLAV")) {
			klav = new MDXAlpha("KLAV","KLAV:Visibility");
			klav.decode(ins);
		} else ins.unread(temp);
		
		ins.read(temp);
		tag = new String(temp);
		if(tag.equals("KLAC")) {
			klac = new MDXScaling("KLAC","KLAC:Color");
			klac.decode(ins);
		} else ins.unread(temp);
		
		ins.read(temp);
		tag = new String(temp);
		if(tag.equals("KLBC")) {
			klbc = new MDXScaling("KLBC","KLBC:AmbColor");
			klbc.decode(ins);
		} else ins.unread(temp);
		
		ins.read(temp);
		tag = new String(temp);
		if(tag.equals("KLBI")) {
			klbi = new MDXAlpha("KLBI","KLBI:AmbIntensity");
			klbi.decode(ins);
		} else ins.unread(temp);
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("TAG : "+getTag());
		sb.append("\n\tELEN : "+nbytesi);
		
		return sb.toString();
	}

	@Override
	public boolean isImplicitTag() {
		// TODO Auto-generated method stub
		return false;
	}
}
